package com.practice.search;

import java.util.ArrayList;

import com.practice.util.FileHelper;

public class DictionaryCutter {
	private final static String DIR = "src/test/resources";

	/**
	 * @param args
	 */
	public static void main(String[] args) {
		new DictionaryCutter().cut();
	}

	private void cut() {
		String content = FileHelper.readFile(DIR + "/WORD.LST");
		String[] words = content.split("\n");
		ArrayList<String>[] collector = new ArrayList[30];
		for (int i=0; i<30; i++) collector[i] = new ArrayList<String>();
		
		for (String word : words) {
			collector[word.length()].add(word);
		}
		
		StringBuilder sb = new StringBuilder();
		for (int i=1; i<30; i++) {
			if (collector[i].size() == 0) continue;
			sb.setLength(0);
			for (String word : collector[i]) {
				sb.append("\n" + word);
			}
			FileHelper.writeFile(DIR + "/WORD" + i + ".LST", sb.substring(1));
		}
	}
}
